// pages/merchant/merchant.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    yue:'¥20960',
    yongjin:'¥8673',
    shouyi:'¥1260',
    notice:'',
    fsid:'',
    validCommission:0,
    invalidCommission:0,
    totalCommission:0,
    todayEarnings:0,
    advertName:"",
    imgUrl:""


  },
  gorouter: function(e) {
        console.log(e.currentTarget.dataset.type)
        wx.navigateTo({
            url: e.currentTarget.dataset.type
        })
    },
    //去我的社区
    gowdsq: function () {
        wx.showToast({
            title: '社区服务暂未开启',
            icon: 'loading',
        })

    },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that=this;
    var validCommission = wx.getStorageSync('validCommission');
    var invalidCommission = wx.getStorageSync('invalidCommission');
console.log("validCommission---" + validCommission);
    console.log("invalidCommission---" + invalidCommission);
    var totalCommission = (parseFloat(validCommission) + parseFloat(invalidCommission)).toFixed(2);
    console.log("totalCommission---" + totalCommission);
    that.setData({
      fsid: options.fsid,
      validCommission: validCommission,
      invalidCommission: invalidCommission,
      totalCommission: totalCommission,
      todayEarnings: wx.getStorageSync('todayEarnings')
    })
  
    //获取所属会员
    wx.request({
      // url: con.index_getread,
      url: 'https://www.brvpmusic.com/api/notice/franchise/list',
      method: 'GET',
      data: {
        'type': 4,
      },
      header: {
        'Content-Type': 'application/json'
      },
      success: function (res) {
        console.log(res.data);
        console.log('返回成功');
        that.setData({
          notice: res.data.body[0].uContent,
        })
      },
      fail: function (res) {
        console.log('返回失败');
      }
    })


    //获取分享的参数（名字和图片）
    wx.request({
      // url: con.index_getread,
      url: 'https://www.brvpmusic.com/api/advertisement/list',
      method: 'GET',
      data: {
        'type': 1,
      },
      header: {
        'Content-Type': 'application/json'
      },
      success: function (res) {
        var advertName = res.data.data[0].advertName;
        var imgUrl = 'https://www.brvpmusic.com'+res.data.data[0].imgUrl;
        console.log(advertName);
        console.log(imgUrl);
        that.setData({
          advertName: advertName,
          imgUrl: imgUrl
        })
      },
      fail: function (res) {
        console.log('返回失败');
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
   onShareAppMessage: function () {
    console.log(this.data.advertName);
    let _data = {
      title: this.data.advertName,
      // path: 'pages/spread/spread?openid=' + wx.getStorageSync('OpenId') + '&promoCode=' + wx.getStorageSync('promoCode') + '&fSellname=' + wx.getStorageSync('fSellname'),
      path: '/pages/start/start?upper_fSid='+wx.getStorageSync('fSid'),
      imageUrl: this.data.imgUrl,
      success: function (res) {
        // 转发成功
      },
      fail: function (res) {
        // 转发失败
      }
    }
    return _data
  },
})